﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Ultima.Xna.Input;
using System.Xml;
using Ultima.Xna.Data;

namespace Ultima.Xna.Graphics.UI
{
    public class GumpRadio : GumpCheckbox, IGumpRadioButton
    {
        private int _groupId;

        public int GroupId
        {
            get { return _groupId; }
            set { _groupId = value; }
        }

        public override bool Checked
        {
            get
            {
                return base.Checked;
            }
            set
            {
                if (value)
                {
                    if (Parent != null)
                    {
                        for (int i = 0; i < Parent.Children.Count; i++)
                        {
                            if (Parent.Children[i] is GumpRadio &&
                                Parent.Children[i] != this && ((GumpRadio)Parent.Children[i]).GroupId == _groupId)
                            {
                                ((GumpRadio)Parent.Children[i]).Checked = false;
                            }
                        }
                    }
                }

                base.Checked = value;
            }
        }

        public GumpRadio(Game game, IUIContainerNode parent)
            : base(game, parent)
        {

        }
    }
}
